package com.ydy.service.impl;

import com.ydy.mapper.CategoryMapper;
import com.ydy.pojo.Category;
import com.ydy.pojo.vo.CategoryVO;
import com.ydy.pojo.vo.NewItemsVO;
import com.ydy.service.CategoryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**商品分类*/
 @Service
public class CategoryServiceImpl implements CategoryService {

    public static final Logger log =
          LoggerFactory.getLogger(CategoryServiceImpl.class);

    @Autowired
    private CategoryMapper categoryMapper;

    /**
    * 查詢所有的一級分類
    * @Title: queryAllRootLevelCategory
    * @author: dy.yin 2022/1/14 9:20
    * @return: {@link List< Category> }
    */
    @Override
    public List<Category> queryAllRootLevelCategory() {
        Category category = new Category();
        category.setType(1);
        log.info("查询所有的以及分类");
        return categoryMapper.select(category);
    }

    /**
     * 根据一级分类查询其子类
     * @Title: querySubCategoryByRootId
     * @author: dy.yin 2022/1/14 9:22
     * @param: [rootCatId]   一级分类id
     * @return: {@link List<CategoryVO> }
     */
    @Override
    public List<CategoryVO> querySubCategoryByRootId(String rootCatId) {
        log.info("根据一级id：{}查询所有子分类");
        return categoryMapper.querySubCategoryByRootId(rootCatId);
    }

    /**
     * 根据一级分类查询最新的6个产品
     * @Title: querySixItemsByRootId
     * @author: dy.yin 2022/1/14 9:23
     * @param: [rootCatId] 一级分类id
     * @return: {@link List<NewItemsVO> }
     */
    @Override
    public List<NewItemsVO> querySixItemsByRootId(String rootCatId) {
        log.info("根据一级id：{}查询最新的6个商品",rootCatId);
        return categoryMapper.querySixItemsByRootId(rootCatId);
    }
}
